/*
* $Id: GetInspectOperation.cpp 2 2009-12-23 13:58:02Z volok-aleksej@yandex.ru $
*
* Copyright 2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "GetInspectOperation.h"
#include "../SqlBinder.h"
#include "../Result.h"
#include "../Tables/TableNames.h"

CGetInspectOperation::CGetInspectOperation(){}
CGetInspectOperation::~CGetInspectOperation(){}

IResult* CGetInspectOperation::GetValue(IDatabase* pDatabase){
	CSqlBinder binder;
	std::tstring strRequest(_T("SELECT * FROM "));
	strRequest = strRequest + INSPECT_TABLE_NAME + _T(" INNER JOIN ") + HOUSINGS_TABLE_NAME + _T(" ON ");
	binder.SetRequest(strRequest + INSPECT_TABLE_NAME + _T(".id_housing=") + HOUSINGS_TABLE_NAME + _T(".id_housing WHERE id_journal=?"));
	binder.SetValue(0, m_content.s_nIdJournal);
	m_content.Clear();
	return FillContent(pDatabase->ExecRequest(binder.GetRequest()));
}

IOperation::i_content* CGetInspectOperation::CreateContent(){
	return new content;
}
CGetInspectOperation::content::content(){
	Clear();
}

CGetInspectOperation::content::content(const content& cont){
	*this = cont;
}

void CGetInspectOperation::content::operator=(const content& cont){
	s_nIdJournal = cont.s_nIdJournal;
	s_nIdHousing = cont.s_nIdHousing;
	s_strNameHousing = cont.s_strNameHousing;
	s_nHoney = cont.s_nHoney;
	s_nBrood = cont.s_nBrood;
	s_nOpenBrood = cont.s_nOpenBrood;
	s_nCloseBrood = cont.s_nCloseBrood;
	s_nGoodsHoney = cont.s_nGoodsHoney;
}

void CGetInspectOperation::content::Clear(){
	s_nIdJournal = 0;
	s_strNameHousing.clear();
	s_nHoney = 0;
	s_nBrood = 0;
	s_nOpenBrood = 0;
	s_nCloseBrood = 0;
	s_nGoodsHoney = 0;
}

void CGetInspectOperation::content::Set(const std::vector<CTableItem>& aContent){
	for(std::vector<CTableItem>::const_iterator it = aContent.begin(); it != aContent.end(); it++){
		if(it->m_strNameColumn == _T("id_journal"))
			s_nIdJournal = _ttoi(it->m_strValueColumn.c_str());
		if(it->m_strNameColumn == _T("name"))
			s_strNameHousing = it->m_strValueColumn;
		if(it->m_strNameColumn == _T("honey"))
			s_nHoney = _ttoi(it->m_strValueColumn.c_str());
		if(it->m_strNameColumn == _T("brood"))
			s_nBrood = _ttoi(it->m_strValueColumn.c_str());
		if(it->m_strNameColumn == _T("open_brood"))
			s_nOpenBrood = _ttoi(it->m_strValueColumn.c_str());
		if(it->m_strNameColumn == _T("close_brood"))
			s_nCloseBrood = _ttoi(it->m_strValueColumn.c_str());
		if(it->m_strNameColumn == _T("goods_honey"))
			s_nGoodsHoney = _ttoi(it->m_strValueColumn.c_str());
		if(it->m_strNameColumn == _T("id_housing"))
			s_nIdHousing = _ttoi(it->m_strValueColumn.c_str());
	}
}
